<template>
		<navbar title="支付失败" :isBack="true"></navbar>
		<view class="" style="padding: 0 30rpx;">
			<view class="" style="display: flex;justify-content: center;align-items: center;margin-top: 100rpx;flex-direction: column;">
				<image src="/static/image/payFail.png" style="width: 160rpx;height: 160rpx;" mode=""></image>
				<view class="" style="margin-top: 20rpx;text-align: center;font-size: 36rpx;font-weight: bold;">
					支付失败
				</view>
				<view class="" style="text-align: center;margin-top: 40rpx;font-size: 32rpx;">
					请您重新支付！
				</view>
			</view>
			<view class="" style="margin-top: 170rpx;display: flex;justify-content: space-between;">
				<view class="" @click="home" style="border-radius: 10rpx;border: 1rpx solid #D2D2D2;height: 98rpx;display: flex;justify-content: center;align-items: center;color: #696969;font-size: 32rpx;width: 336rpx;">
					返回首页
				</view>
				<view class="" @click="pay" style="border-radius: 10rpx;border: 1rpx solid #5062A7;height: 98rpx;display: flex;justify-content: center;align-items: center;color: #5062A7;font-size: 32rpx;width: 336rpx;">
					重新支付
				</view>
			</view>
		</view>
</template>

<script setup lang="ts">
	import { onLoad, onShow } from '@dcloudio/uni-app'
	import {ref,reactive} from 'vue';
		import tools from '@/utils/tools'
	import {cashier,orderPay} from '@/service/api/index'
	import {speedOrderPay,speedCashier} from '@/service/api/speed'
	import {cityOrderPay} from '@/service/api/city'
	const home = ()=>{
		uni.switchTab({
			url:'/pages/match/index'
		})
	}
	const param = reactive({id:"",type:0})
	onLoad((options)=>{
		param.id = options.id
		if(options.type){
			param.type = options.type;
		}
	})
	const pay = async() => {
		//七天速成支付 
		if(param.type == 1){
			speedPay()
			return
		}
		//城市巡回
		if(param.type == 2){
			cityPay();
			return
		}
		const res = await orderPay({id:param.id});
		if(res.code == 1){
			tools.requestPayment(res.msg).then((result)=>{
				console.log('正常' + result);
				uni.redirectTo({
					url: '/pagesB/order/paySuc?type=' + param.type
				})
			}).catch((err)=>{
				console.log('失败' + err);
				uni.redirectTo({
					url: '/pagesB/order/payFail?id=' + param.id + '&type=' + param.type
				})
			});
		}
		return	
	}
	const speedPay = async()=>{
		const res = await speedOrderPay({id:param.id})
		if(res.code == 1){
			tools.requestPayment(res.msg).then((result)=>{
				console.log('正常' + result);
				uni.redirectTo({
					url: '/pagesB/order/paySuc?type=' + param.type
				})
			}).catch((err)=>{
				console.log('失败' + err);
				tools.navTo('/pagesB/order/payFail?id=' + param.id + '&type=' + param.type,4)
				 
			});
		}
	}
	const cityPay = async()=>{
		const res = await cityOrderPay({id:param.id})
		if(res.code == 1){
			tools.requestPayment(res.msg).then((result)=>{
				console.log('正常' + result);
				uni.redirectTo({
					url: '/pagesB/order/paySuc?type=' + param.type
				})
			}).catch((err)=>{
				console.log('失败' + err);
				tools.navTo('/pagesB/order/payFail?id=' + param.id + '&type=' + param.type,4)
				 
			});
		}
	}
</script>

<style>
</style>